package org.mybatis.context;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.mybatis.config.JavaGeneratorConfiguration;
import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.config.Context;
import org.mybatis.generator.config.ModelType;

import java.util.List;

/**
 * 功能描述
 *
 * @author jy
 * @date 2019/3/7
 * @description
 * @project management
 */
@Data
@EqualsAndHashCode(callSuper=true)
public class ContextOverride extends Context {

    //添加ServiceGeneratorConfiguration
    private JavaGeneratorConfiguration serviceGeneratorConfiguration;

    //添加ServiceImplGeneratorConfiguration
    private JavaGeneratorConfiguration serviceImplGeneratorConfiguration;

    //添加controllerGeneratorConfiguration
    private JavaGeneratorConfiguration controllerGeneratorConfiguration;

    ContextOverride(ModelType defaultModelType) {
        super(defaultModelType);
    }

    @Override
    public void validate(List<String> errors) {
        super.validate(errors);
    }

    public XmlElement toXmlElement() {
        XmlElement xmlElement = super.toXmlElement();
        if (serviceGeneratorConfiguration != null)
            xmlElement.addElement(serviceGeneratorConfiguration.toXmlElement());
        if (serviceImplGeneratorConfiguration != null)
            xmlElement.addElement(serviceImplGeneratorConfiguration.toXmlElement());
        if (controllerGeneratorConfiguration != null)
            xmlElement.addElement(controllerGeneratorConfiguration.toXmlElement());
        return xmlElement;
    }
}